Skip to content

Conversation

@0f-0b
Copy link

@0f-0b 0f-0b commented Nov 23, 2025

This change eliminates the two constants (the abs mask and infinity), reducing code size at hopefully no performance cost. It works because x - x is always +0 when x is finite, and is NaN if and only if x is infinite or NaN.

Generated aarch64 assembly for f32 compared to the current implementation:

is_finite:
    fsub  s0, s0, s0
    fcmp  s0, s0
    cset  w0, vc
    ret

is_finite_std:
    fmov  w9, s0
    mov   w8, #0x7f800000
    and   w9, w9, #0x7fffffff
    cmp   w9, w8
    cset  w0, lt
    ret

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 23, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 23, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@quaternic
Copy link
Contributor

I'm not convinced that this is an improvement. The existing implementation (abs(x) < INFINITY) is obviously correct, and LLVM optimizes it to a single llvm.is.fpclass intrinsic call, where it should have all the information to generate ideal code for any target. If it doesn't, that's where this should be patched.

In fact, it looks like someone else has just opened such an issue: llvm/llvm-project#169270

@0f-0b 0f-0b closed this Nov 24, 2025
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 24, 2025
@0f-0b 0f-0b deleted the is-finite branch November 24, 2025 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants